home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-07-28 | 5.0 KB | 183 lines | [TEXT/MPS ] |
- /*
- IconWDEF.cp
-
- Implementation of Icon window definition class methods.
-
- by Patrick Beard.
-
- ©1990 by Patrick C. Beard. All rights reserved.
- */
-
- #ifndef __ICONWDEF__
- #include "IconWDEF.h"
- #endif
-
- #include <Events.h>
-
- // bitmap for the iconified view.
-
- static unsigned short IconBits[] = {
- 0x3FFF, 0xFFFF, 0x2000, 0x0001, 0xFFFF, 0xFFFF, 0xE000, 0x0001,
- 0xFFFF, 0xFFFF, 0xE000, 0x0001, 0xE000, 0x0001, 0xE000, 0x0001,
- 0xE000, 0x0001, 0xE000, 0x0001, 0xE000, 0x0001, 0xE000, 0x0001,
- 0xE000, 0x0001, 0xE000, 0x0001, 0xE000, 0x0001, 0xE000, 0x0001,
- 0xE000, 0x0001, 0xE000, 0x0001, 0xE000, 0x0001, 0xE000, 0x0001,
- 0xE000, 0x0001, 0xE000, 0x0001, 0xE000, 0x0001, 0xE000, 0x0001,
- 0xE000, 0x0001, 0xE000, 0x0001, 0xE000, 0x0001, 0xE000, 0x0001,
- 0xE000, 0x0001, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFC, 0xFFFF, 0xFFFC
- };
-
- static Boolean OptionKeyDown()
- {
- // see if the command key is down.
- KeyMap theKeys;
- GetKeys(theKeys);
- return (theKeys[1] & 4L) != 0;
- }
-
- // initialize the state of the window.
-
- void IconWindowDef::New(WindowPeek theWindow)
- {
- WindowFrame::New(theWindow);
-
- iconified = false;
- everIconified = false;
- requestingStateChange = false;
- calcRgnsCount = 0;
-
- GrafPtr oldPort; GetPort(&oldPort);
- SetPort((GrafPtr)itsWindow);
-
- // initialize the default zoom states of the window.
- WStateDataHandle states = (WStateDataHandle)itsWindow->dataHandle;
- if(states) {
- itsWindow->spareFlag = true; // zooming enabled.
- Rect r = itsWindow->port.portRect;
- LocalToGlobal(&topLeft(r));
- LocalToGlobal(&botRight(r));
- (**states).userState = r; // normal size.
- r.bottom = r.top + 1;
- r.right = r.left + 1;
- (**states).stdState = r; // icon size.
- }
-
- SetPort(oldPort);
- }
-
- void IconWindowDef::CalcRgns()
- {
- GrafPtr oldPort; GetPort(&oldPort);
- SetPort((GrafPtr)itsWindow);
- WStateDataHandle states = (WStateDataHandle)itsWindow->dataHandle;
- Rect r = itsWindow->port.portRect;
- LocalToGlobal(&topLeft(r));
- LocalToGlobal(&botRight(r));
- if(requestingStateChange) {
- if(--calcRgnsCount == 0) {
- requestingStateChange = false;
- iconified = !iconified;
- }
- }
- if(iconified) {
- Rect portRect = itsWindow->port.portRect;
- LocalToGlobal(&topLeft(portRect));
- LocalToGlobal(&botRight(portRect));
- SetEmptyRgn(itsWindow->contRgn);
- portRect.right = portRect.left + 32;
- portRect.bottom = portRect.top + 32;
- RectRgn(itsWindow->strucRgn, &portRect);
- RgnHandle notchRgn = NewRgn();
- SetRectRgn(notchRgn, portRect.left, portRect.top, portRect.left+2, portRect.top+2);
- DiffRgn(itsWindow->strucRgn, notchRgn, itsWindow->strucRgn);
- SetRectRgn(notchRgn, portRect.right-2, portRect.bottom-2, portRect.right, portRect.bottom);
- DiffRgn(itsWindow->strucRgn, notchRgn, itsWindow->strucRgn);
- DisposeRgn(notchRgn);
- } else {
- WindowFrame::CalcRgns();
- }
- SetPort(oldPort);
- }
-
- void IconWindowDef::DrawFrame()
- {
- if(!itsWindow->visible)
- return;
-
- if(iconified) {
- // draw the window as an icon.
- GrafPtr currPort; GetPort(&currPort);
- BitMap windIcon = { (Ptr)IconBits, 4, { 0, 0, 32, 32 } };
- Rect iconRect = (**itsWindow->strucRgn).rgnBBox;
- CopyBits(&windIcon, &currPort->portBits, &windIcon.bounds, &iconRect, srcCopy, itsWindow->strucRgn);
- } else {
- WindowFrame::DrawFrame();
- // draw in zoom, or iconify box.
- if(itsWindow->hilited) {
- // recompute the iconifyRgn.
- iconifyRect = (**itsWindow->strucRgn).rgnBBox;
- short insetAmount = 5 + GetWVariant((WindowPtr)itsWindow);
- iconifyRect.bottom = iconifyRect.top + insetAmount;
- iconifyRect.left = iconifyRect.right - insetAmount;
- InsetRect(&iconifyRect, 1, 1);
- Pattern iconifyPattern = { 0xAA, 0xAB, 0xA8, 0xAF, 0xA0, 0xBF, 0x80, 0xFF };
- FillRect(&iconifyRect, iconifyPattern);
- }
- }
- }
-
- long IconWindowDef::Hit(Point& whereHit)
- {
- GrafPtr currPort; GetPort(&currPort);
- SetPort(&itsWindow->port);
- Rect r = itsWindow->port.portRect;
- LocalToGlobal(&topLeft(r));
- LocalToGlobal(&botRight(r));
- SetPort(currPort);
-
- WStateDataHandle states = (WStateDataHandle)itsWindow->dataHandle;
- if(iconified) {
- (**states).stdState = r; // icon size.
- } else {
- (**states).userState = r; // normal size.
- }
-
- // option-key is used to change state of the window.
- if(OptionKeyDown()) {
- if(iconified) {
- if(!requestingStateChange) {
- requestingStateChange = true;
- calcRgnsCount = 2;
- }
- return wInZoomIn;
- } else {
- // recompute the iconifyRgn.
- iconifyRect = (**itsWindow->strucRgn).rgnBBox;
- short insetAmount = 5 + GetWVariant((WindowPtr)itsWindow);
- iconifyRect.bottom = iconifyRect.top + insetAmount;
- iconifyRect.left = iconifyRect.right - insetAmount;
- InsetRect(&iconifyRect, 1, 1);
- if(PtInRect(whereHit, &iconifyRect)) {
- // make iconified location same place window is now.
- if(!everIconified) {
- r.left = r.right - 32;
- r.bottom = r.top + 1;
- (**states).stdState = r;
- everIconified = true;
- }
- if(!requestingStateChange) {
- requestingStateChange = true;
- calcRgnsCount = 2;
- }
- return wInZoomOut;
- }
- }
- }
-
- // if iconified, we handle hit testing, if not, normal window does.
- if(iconified)
- return wInDrag;
- else
- return WindowFrame::Hit(whereHit);
- }
-